package org.hospital.pojo;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

/**
 * TPatient entity. @author MyEclipse Persistence Tools
 */

@Entity
@Table(name="t_patient")
public class TPatient implements java.io.Serializable {

	// Fields
	private Integer patientId;
	private String name;
	private short gender;
	private short age;
	private String idNum;
	private String addr;
	private String tel;
	private Set<TFirVisit> firVisit = new HashSet<TFirVisit>();

	// Constructors
	@OneToMany(mappedBy="patient", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) 
	public Set<TFirVisit> getFirVisit() {
		return firVisit;
	}

	public void setFirVisit(Set<TFirVisit> firVisit) {
		this.firVisit = firVisit;
	}
	
	public void addFirVisit(TFirVisit firVisit) {   
        if (!this.firVisit.contains(firVisit)) {   
            this.firVisit.add(firVisit);   
            firVisit.setPatient(this);   
        }   
    }   
  
    public void removeFirVisit(TFirVisit firVisit) {   
    	firVisit.setPatient(null);   
        this.firVisit.remove(firVisit);   
    }

	/** default constructor */
	public TPatient() {
	}

	/** full constructor */
	public TPatient(String name, short gender, short age, String idNum,
			String addr, String tel) {
		this.name = name;
		this.gender = gender;
		this.age = age;
		this.idNum = idNum;
		this.addr = addr;
		this.tel = tel;
	}

	// Property accessors
	@Id
	@Column(name="PATIENT_ID",insertable=true,nullable=false,updatable=true)
    @GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getPatientId() {
		return this.patientId;
	}

	public void setPatientId(Integer userId) {
		this.patientId = userId;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public short getGender() {
		return this.gender;
	}

	public void setGender(short gender) {
		this.gender = gender;
	}

	public short getAge() {
		return this.age;
	}

	public void setAge(short age) {
		this.age = age;
	}
	
	@Column(name="ID_NUM")
	public String getIdNum() {
		return this.idNum;
	}

	public void setIdNum(String idNum) {
		this.idNum = idNum;
	}

	public String getAddr() {
		return this.addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public String getTel() {
		return this.tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

}